// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview This file defines the mimic namespace and corresponding
 * initialization function that each mimic extension will call when its
 * overlay is added to each XUL document.
 *
 * Each time a new browser window is opened the XUL document is created and
 * each extension's overlays are applied.  At this point, the generic mimic
 * namespace is created once for however many mimic extensions are loaded.
 * Once the init function is created, each extension will call the init
 * function with their unique alias defined in chrome.manifest that denotes
 * the folder path to the root of their extension.  This alias is used to
 * create unique sandboxes for each extension.
 *
 * @author jasonstredwick@google.com (Jason Stredwick)
 */


/**
 * Add the mimic namespace unless someone else already claimed it.  If it is
 * already claimed then nothing happens and the extension is not run.
 */
if (typeof(mimic) == 'undefined') {
  var mimic = {};

  // Import will add to the mimic namespace.
  Components.utils.import('resource://mimic/mimic.js', mimic);
}


/**
 * Adds a mimic extension if functionality is available.  It will not be
 * available if the namespace was created first by a non-mimic extension.
 */
if (mimic && typeof(mimic.addExtension) == 'function') {
  // TODO (jasonstredwick): 'extension' should be generalized to the alias
  // specified in chrome.manifest.  The issue is how to obtain the alias
  // programmatically.  For now, I require the user or BUILD.mimic build rule
  // to change the correct alias.  Defaults to extension_alias.
  mimic.addExtension('extension_alias');
}

